package controllers

import (
	"ginstart/models/mysql"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func CreateVideo(c *gin.Context) {
	userId, _ := c.Get("userId")
	userIds, _ := strconv.Atoi(userId.(string))
	name := c.PostForm("name")
	time := c.PostForm("time")
	video := mysql.Video{
		UserId: userIds,
		Name:   name,
		Time:   time,
	}
	err := video.Create()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"response": JsonRes{
				Code:    500,
				Message: "视频发布失败",
				Data:    nil,
			},
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"response": JsonRes{
			Code:    500,
			Message: "视频发布成功",
			Data:    video.ID,
		},
	})
	return
}
